<template>
  <div class="app-container">
    <div class="filter-container">
     <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="">
          <el-input style="width:300px;" class="filter-item" placeholder="请输入用户名" v-model="listQuery.userName"></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-input style="width:300px;" class="filter-item" placeholder="请输入手机号" v-model="listQuery.phone"></el-input>
        </el-form-item>
        <el-form-item label="">
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getList">搜索</el-button>
        </el-form-item>
        <el-form-item label="">
          <el-button class="filter-item" type="primary" @click="handleCreate()"  icon="el-icon-plus">新增</el-button>
        </el-form-item>
     </el-form>
    </div>
    <el-table :data="list" v-loading="listLoading" element-loading-text="数据正在加载" border>
      <el-table-column align="center" label="用户名" prop="userName"/>
      <el-table-column align="center" label="真实姓名" prop="trueName"/>
      <el-table-column align="center" label="电话" prop="phone"/>
      <el-table-column align="center" label="状态" prop="status">
        <template slot-scope="scope">
          <span>{{scope.row.status}}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="handleCreate(scope.row.id)">编辑</el-button>
          <el-button v-if="scope.row.status!='deleted'" size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" 
        :total="total" 
        :page.sync="listQuery.currPage" 
        :limit.sync="listQuery.pageSize"
        @pagination="getList"
      />
    <!-- 新增/编辑 对话框 -->
    <edit-user ref="dialog"  @refreshDataList="getList"  v-if="addOrUpdateVisible"></edit-user>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination";
import editDialog from './edit_user'
import { pageUser,delUser} from '@/api/auth/user'
export default {
  components: {
    Pagination,
    'edit-user': editDialog
  },
  data() {
    return {
      list: null,
      total: 0,
      listLoading: true,
      addOrUpdateVisible: false,
      listQuery: {
        currPage: 1,
        pageSize: 10,
        userName:"",
        phone:""
      },
      dialog: {
        visible: false,
        temp: {
          account: '',
          username: '',
          password: '',
          realName: '',
          sex: '',
          phone: '',
          email: ''
        }
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      var that = this
      that.listLoading = true
      pageUser(that.listQuery).then(res => {
        that.listLoading = false
        that.list = res.data.list
        that.total = res.data.totalCount
      }).catch(() => {})
    },
    handleCreate(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.dialog.selectList(id)
      })
    },
    handleDelete(row) {
      this.$confirm('确认删除该记录吗?', '提示', {
        type: 'warning'
      }).then(() => {
        delUser(row.id ).then(res => {
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          })
          this.getList()
        })
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>
    .btn-container{
        margin-bottom: 10px;
    }
</style>
